package ch09;

public class _18_StringCount {
	private int count;
	private String source = "";

	public _18_StringCount(String source) {
		this.source = source;
	}

	public int stringCount(String s) {
		return stringCount(s, 0);
	}

	public int stringCount(String s, int pos) {
		int index = 0;
		if (s == null || s.length() == 0) return 0;
		if ((index = source.indexOf(s, pos)) != -1) {
			count++;
			stringCount(s, index + s.length());
		}
		return count;
	}

	public static void main(String[] args) {
		String str = "aabbccAABBCCaa";	
		_18_StringCount sc = new _18_StringCount(str);
		System.out.println("found " + sc.stringCount("aa") + " aa."); // found 2 aa.
	}
}